package org.fanximall.erp.system.application.service.login;


import org.fanximall.erp.common.exception.ClientException;
import org.fanximall.erp.common.utils.MessageUtils;
import org.fanximall.erp.system.domain.enums.MessageCodeEnum;
import org.fanximall.erp.system.domain.aggregate.UserAggregate;
import org.fanximall.erp.system.domain.repository.UserRepository;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @author :  william
 * @version :  V1.0  created in 2024/4/22
 */
@Component
public class UserDetailsServiceImpl implements UserDetailsService {

    @Resource
    private UserRepository userRepository;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserAggregate user = userRepository.findByUserName(username);
        Optional.ofNullable(user).orElseThrow(() -> new ClientException(MessageUtils.message(MessageCodeEnum.USER_NOT_EXISTS.getCode())));
        user.checkUsersStatus();

        return null;
    }
}
